using System.Collections;
using System;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;
using Random = UnityEngine.Random;
//using UnityEngine.Localization;
using UnityEngine.UI;
using System.Threading.Tasks;

public static class UtilBase
{
    public static class ColorUtil
    {
        public static Color TryParseHtmlString(string colorStr)
        {
            ColorUtility.TryParseHtmlString("#" + colorStr, out var color);
            return color;
        }

        public static Color WhitClear()
        {
            ColorUtility.TryParseHtmlString("FFFFFF00", out var color);
            return color;
        }
    }
    public static class TransRotaUtil
    {
        //public static Quaternion WhitClear()
        //{
        //    ColorUtility.TryParseHtmlString("FFFFFF00", out var color);
        //    return color;
        //}
    }


    public static class Vector3Util
    {
        public static Vector3 tmpPos = Vector3.zero;
        public static Vector3 EulToV3(Vector3 center, float eulZ, float dist)
        {
            float angle = eulZ * Mathf.Deg2Rad; // 将角度转换为弧度  
            tmpPos.y = center.y + dist * Mathf.Cos(-angle);
            tmpPos.x = center.x + dist * Mathf.Sin(-angle);
            return tmpPos;
        }

        public static Vector3 GetBezier2ControlPoint(Vector3 pointA, Vector3 pointB)
        {
            Vector3 center = (pointA + pointB) / 2;
            Vector3 result = Vector3.zero;
            result.x = Mathf.Abs(pointA.x - center.x) * 0.6f;
            result.y = Mathf.Abs(pointA.y - center.y) * 0.6f;
            float randomNum = Mathf.Max(result.x, result.y);
            result.x = Random.Range(-randomNum, randomNum);
            result.y = Random.Range(-randomNum, randomNum);
            return result + center;
        }

        /// <summary>
        /// 获取贝塞尔曲线路径
        /// </summary>
        /// <param name="startPos"></param>
        /// <param name="controlPos"></param>
        /// <param name="endPos"></param>
        /// <param name="length"></param>
        /// <returns></returns>
        public static Vector3[] Bezier2Path(Vector3 startPos, Vector3 controlPos, Vector3 endPos, int length)
        {
            Vector3[] path = new Vector3[length];
            for (int i = 1; i <= length; i++)
            {
                float t = 1f * i / length;
                path[i - 1] = Bezier2(startPos, controlPos, endPos, t);
            }
            return path;
        }

        public static Vector3[] Bezier2PathFromUp(Vector3 startPos, Vector3 endPos, int length)
        {
            Vector3 ctrlPos = (startPos + startPos) * 0.5f;
            ctrlPos.y += 20;
            return Bezier2Path(startPos, ctrlPos, endPos, length);
        }

        public static Vector3[] Bezier2Path(Vector3 startPos, Vector3 endPos, int length)
        {
            Vector3 controlPos = GetBezier2ControlPoint(startPos, endPos);
            return Bezier2Path(startPos, controlPos, endPos, length);
        }

        // 2阶贝塞尔曲线
        public static Vector3 Bezier2(Vector3 startPos, Vector3 controlPos, Vector3 endPos, float t)
        {
            return (1 - t) * (1 - t) * startPos + 2 * t * (1 - t) * controlPos + t * t * endPos;
        }

    }


    public static class ActionFunUtil
    {
        public static Func<Task> OnSuperMulti;
    }
    //public static class LangUtil
    //{
    //    static LocalizedString LString = new LocalizedString("LangsTable", "");
    //    //static Dictionary<string,Text,object[]> LocalizedTxts = new Dictionary<string, Text, object[]>();

    //    //public static void SetTextLocalized(Text txt, string key)
    //    //{
    //    //    if (true)
    //    //    {

    //    //    }
    //    //    LocalizedTxts.Add(txt);
    //    //    txt.text = GetStr
    //    //}

    //    public static string GetStr(string key)
    //    {
    //        LString.TableEntryReference = key;
    //        return LString.GetLocalizedString();
    //    }
    //    public static string GetStr(string key, params object[] s)
    //    {
    //        LString.TableEntryReference = key;
    //        return LString.GetLocalizedString(s);
    //    }
    //}
    public static class TimeUitl
    {

        private static Dictionary<string, int> RecTimeDic = new Dictionary<string, int>();

        public static void ResetRecTime(string str)
        {
            //RecTimeDic.TrySet(str,(int)Time.time);
            RecTimeDic[str] = (int)Time.time;
        }


        public static int GetRecTime(string str)
        {
            int time = (int)Time.time;
            if (RecTimeDic.ContainsKey(str))
                return time - RecTimeDic[str];
            else
            {
                Debug.LogError("没有这个Key == " + str);
                return 0;
            }

        }

        public static string IntToHMS(int time)//转时分秒
        {
            return TimeSpan.FromSeconds(time).ToString(@"hh\:mm\:ss");
        }
    }
}
